(function(){"use strict";BX.namespace("BX.Landing.UI.Card");var t=BX.Landing.Utils.create;var i=BX.Landing.Utils.append;var e=BX.Landing.Utils.prepend;var n=BX.Landing.Utils.remove;var t=BX.Landing.Utils.create;function s(t,i){return{image:t.link,credit:{},dimensions:{width:t.image.width,height:t.image.height},onClick:i.onPictureChange.bind(i,t.link)}}function r(t,i){return t.map(function(t){return s(t,i)})}BX.Landing.UI.Card.Google=function(t){BX.Landing.UI.Card.Library.apply(this,arguments);this.page=1;this.query="";this.loader=new BX.Loader({target:this.body,offset:{top:"12%"}});this.client=BX.Landing.Client.Google.getInstance();this.onSearchWithDebounce=BX.debounce(this.onSearchWithDebounce,1e3,this);this.showPopular()};BX.Landing.UI.Card.Google.prototype={constructor:BX.Landing.UI.Card.Google,__proto__:BX.Landing.UI.Card.Library.prototype,onLoadMore:function(){this.appendSearch()},appendSearch:function(){this.page+=1;this.state="search";this.showBottomLoader();this.hideLoadMore();this.hideError();this.client.search(this.query,this.page).then(function(t){this.hideBottomLoader();this.showLoadMore();this.renderItems(r(t,this))}.bind(this)).catch(this.showError.bind(this))},showPopular:function(){this.hideError();this.showLoader();this.query="Nature";this.state="popular";this.onSearchWithDebounce("Nature");if(BX.Landing.Client.Google.allowKeyChange){this.showSettingsButton()}else{this.hideSettingsButton()}},showSettingsButton:function(){if(!this.settingsButton){this.settingsButton=BX.create("a",{props:{className:"ui-btn ui-btn-xs ui-btn-light-border ui-btn-icon-setting landing-google-settings-button"},html:BX.Landing.Loc.getMessage("LANDING_GOOGLE_IMAGES_CHANGE_KEY_BUTTON"),events:{click:this.onSettingsClick.bind(this)}});this.body.appendChild(this.settingsButton)}this.settingsButton.hidden=false},hideSettingsButton:function(){if(this.settingsButton){this.settingsButton.hidden=true}},onSettingsClick:function(t){t.preventDefault();if(BX.Landing.Client.Google.allowKeyChange){BX.Landing.UI.Panel.GoogleImagesSettings.getInstance().show().then(function(){this.showPopular();this.searchField.input.innerHTML=""}.bind(this))}},onSearchInput:function(t){this.hideError();var i=t.getValue();if(!!i&&i.length){this.query=i;this.page=1;this.state="search";this.showLoader();this.onSearchWithDebounce(i);return}if(this.state!=="popular"){this.showPopular()}},onSearchWithDebounce:function(t){this.hideError();this.client.search(t).then(function(t){this.hideLoader();this.clearItems();this.hideEmptyResult();if(t.length===0){this.showEmptyResult();this.hideLoadMore();return}this.renderItems(r(t,this));this.showLoadMore();if(BX.Landing.Client.Google.allowKeyChange){this.showSettingsButton()}else{this.hideSettingsButton()}}.bind(this)).catch(this.showError.bind(this))},onPictureChange:function(t){var i=BX.util.add_url_param("/bitrix/tools/landing/proxy.php",{sessid:BX.bitrix_sessid(),url:t});this.onChange({link:i,ext:BX.util.getExtension(t),name:BX.Landing.Utils.getFileName(t)})},createKeyError:function(){return t("div",{props:{className:"ui-alert ui-alert-warning"},children:[t("span",{props:{className:"ui-alert-message"},html:BX.Landing.Loc.getMessage("LANDING_IMAGES_PANEL_KEY_ERROR")})]})},createError:function(){return t("div",{props:{className:"ui-alert ui-alert-danger"},children:[t("span",{props:{className:"ui-alert-message"},html:BX.Landing.Loc.getMessage("LANDING_IMAGES_PANEL_GOOGLE_ERROR")})]})},hideError:function(){BX.Landing.UI.Card.Library.prototype.hideError.call(this);if(this.error){n(this.error)}},showError:function(){if(!BX.Landing.Client.Google.key){this.error=this.createKeyError()}else{this.error=this.createError()}BX.insertAfter(this.error,this.imageList);BX.Landing.UI.Card.Library.prototype.showError.call(this)}}})();
//# sourceMappingURL=google_images_card.map.js